package login

import (
	"context"
	v1 "donkey-admin/api/role/v1"
	"donkey-admin/internal/dao"
	"donkey-admin/internal/model/entity"
)

func (s *sRole) RoleGetAll(ctx context.Context, req *v1.RoleGetAllReq) (res *v1.RoleGetAllRes, err error) {

	var Roles []entity.SysRole
	count := 0
	err = dao.SysRole.Ctx(ctx).Page(req.Page, req.PageSize).ScanAndCount(&Roles, &count, true)
	if err != nil {
		return nil, err
	}

	return &v1.RoleGetAllRes{
		Rows:     Roles,
		Page:     req.Page,
		PageSize: req.PageSize,
		Total:    count,
	}, nil
}
